﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FreeDream.Common
{
    public abstract class SingletonBase<T> where T : class
    {
        // 懒加载
        class Nested
        {
            // 创建模板类实例，参数2设为true表示支持私有构造函数
            internal static readonly T instance = Activator.CreateInstance(typeof(T), true) as T;
        }
        private readonly static object _lockObj = new object();
        private static T instance = null;
        public static T Instance
        {
            get
            {
                lock (_lockObj)
                {
                    if (instance == null)
                    {
                        return instance = Nested.instance;
                    }
                    return instance;
                }
            }
        }
    }
}
